home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group00b.txt / 000101_icon-group-sender_Tue Oct 24 16:46:41 2000.msg < prev    next >
Internet Message Format  |  2001-01-03  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id e9ONkWg25699
  4.     for icon-group-addresses; Tue, 24 Oct 2000 16:46:32 -0700 (MST)
  5. Message-Id: <200010242346.e9ONkWg25699@baskerville.CS.Arizona.EDU>
  6. Date: Tue, 24 Oct 2000 15:48:41 -0500
  7. From: "Charles Hethcoat" <CHETHCOA@oss.oceaneering.com>
  8. To: <icon-group@cs.arizona.edu>
  9. Subject: Re: counting lines
  10. Content-Disposition: inline
  11. X-Guinevere: 1.0.13 ; Oceaneering Int'l
  12. X-MIME-Autoconverted: from quoted-printable to 8bit by baskerville.CS.Arizona.EDU id e9OKm7324919
  13. Errors-To: icon-group-errors@cs.arizona.edu
  14. Status: RO
  15. Content-Length: 1617
  16.  
  17. >>> Parvinder Kaur <kaurp@cs.ucdavis.edu> 00-10-24 11:10:12 AM >>> wrote:
  18. Hi,
  19.   I have another problem that I could use help figuring out.  I'm
  20. suppose to count the number of lines in a text.  The lines should be
  21. stored in a table as the key and it's associated value is the number of
  22. times it occurred within the text. i.e.
  23.  Hi there
  24.  How are you 
  25.  Hi there 
  26. will look like this
  27.  Hi there 2
  28.  How are you 1
  29. Any help or suggestions will be greatly appreciated.
  30. Thanks,
  31.  Cos :)
  32. >>>
  33.  
  34. Oh, what fun!  Here is my solution, coded for clarity, I hope:
  35.  
  36. procedure main()
  37.     t := table(0)
  38.     while line := read() do {
  39.         t[line] +:= 1
  40.     }
  41.     every line := key(t) do
  42.         write(line, " ", t[line])
  43.     exit()
  44. end
  45.  
  46. which, on reading
  47.  
  48. Hi there
  49. How are you 
  50. Hi there<EOF>
  51.  
  52. writes
  53.  
  54. How are you  1
  55. Hi there 2
  56.  
  57. However, on reading
  58.  
  59. Hi there
  60. How are you 
  61. Hi there
  62. <EOF>
  63.  
  64. writes
  65.  
  66.  1
  67. How are you  1
  68. Hi there 2
  69.  
  70. In other words, watch out for the empty line that might be found at the end!
  71.  
  72. By the way, the two supposedly identical lines in your sample data were not.  One of them had a trailing blank at the end!  I had to edit it to get your intended result.
  73.  
  74. Charles Hethcoat
  75.  
  76. >>> Parvinder Kaur <kaurp@cs.ucdavis.edu> 00-10-24 11:10:12 AM >>>
  77. Hi,
  78.   I have another problem that I could use help figuring out.  I'm
  79. suppose to count the number of lines in a text.  The lines should be
  80. stored in a table as the key and it's associated value is the number of
  81. times it occurred within the text. i.e.
  82.  Hi there
  83.  How are you 
  84.  Hi there 
  85. will look like this
  86.  Hi there 2
  87.  How are you 1
  88. Any help or suggestions will be greatly appreciated.
  89. Thanks,
  90.  Cos :)
  91.  
  92.  
  93.  
  94.